<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //数组拷贝
      //   var hobby1 = ['游泳', '吃饭'];
      //   var hobby2 = [];
      //   for (var i = 0; i < hobby1.length; i++) {
      //     hobby2.push(hobby1[i]);
      //   }
      //   console.log(hobby1);
      //   console.log(hobby2);

    //   function deepCopy(arr) {
    //     var result = [];
    //     for (var i = 0; i < arr.length; i++) {
    //       result.push(arr[i]);
    //     }
    //     return result;
    //   }

    //   var hobby1 = ['游泳', '吃饭'];
    //   var habby2 = deepCopy(hobby1);
    //   console.log(a);
    //   console.log(hobby1 === hobby2)

      //对象拷贝
    //   var obj1 = {name :'小三', age : 24}
    //   var obj2 = {}
    //   for(var k in obj1){
    //     obj2[k] = obj1[k]
    //   }
    //   console.log(obj2);
    //   console.log(obj1);

    function deepCopy(obj){
        var result = {}
        for(var k in obj){
            result[k] = obj[k]
        }
        return result
    }
    var obj1 = {name :'小三', age : 24}
    var obj2 = deepCopy(obj1)
    console.log(obj1)
    console.log(obj2 )
    </script>
  </body>
</html>
